package net;

import java.lang.reflect.InvocationTargetException;

public class StateUpdate
{
	public void execute() {
		this.timestamp = new java.util.Date();
		try {
			for (GameStateChange<?> c : changes)
				c.execute();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		}
	}

	public StateUpdate getInverse() {
		StateUpdate inverse = new StateUpdate();
		for (GameStateChange<?> c : changes)
			inverse.changes.add(0, c.getInverse());
		return inverse;
	}

	public java.util.List<GameStateChange> getChanges() {
		return java.util.Collections.unmodifiableList(changes);
	}

	public void addChange(GameStateChange change) {
		changes.add(change);
	}

	public void setChanges(java.util.List<GameStateChange> changes) {
		this.changes.clear();
		this.changes.addAll(changes);
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String name) {
		this.message = name;
	}

	public java.util.Date getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(java.util.Date timestamp) {
		this.timestamp = timestamp;
	}

	public boolean isEmpty() {
		return changes.isEmpty();
	}

	private java.util.List<GameStateChange> changes = new java.util.LinkedList<GameStateChange>();
	private String message;
	private java.util.Date timestamp;
}